package com.ruoyi.strategwithtype.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.vo.StrategyTypeVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.strategwithtype.domain.StrategyType;
import com.ruoyi.strategwithtype.service.IStrategyTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 策略和类型的中间表Controller
 *
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/strategyType")
public class StrategyTypeController extends BaseController
{
    @Autowired
    private IStrategyTypeService strategyTypeService;

    /**
     * 查询策略和类型的中间表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StrategyType strategyType)
    {
        startPage();
        List<StrategyTypeVo> list = strategyTypeService.selectStrategyTypeList(strategyType);
        return getDataTable(list);
    }

    /**
     * 导出策略和类型的中间表列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, StrategyType strategyType)
    {
        List<StrategyTypeVo> list = strategyTypeService.selectStrategyTypeList(strategyType);
        ExcelUtil<StrategyTypeVo> util = new ExcelUtil<StrategyTypeVo>(StrategyTypeVo.class);
        util.exportExcel(response, list, "策略和类型的中间表数据");
    }

    /**
     * 获取策略和类型的中间表详细信息
     */
    @GetMapping(value = "/selectOne/{strategyId}")
    public AjaxResult getInfo(@PathVariable("strategyId") Integer strategyId)
    {
        return success(strategyTypeService.selectStrategyTypeByStrategyId(strategyId));
    }

    /**
     * 新增策略和类型的中间表
     */

    @PostMapping("/add")
    public AjaxResult add(@RequestBody StrategyType strategyType)
    {
        return toAjax(strategyTypeService.insertStrategyType(strategyType));
    }

    /**
     * 修改策略和类型的中间表
     */

    @PutMapping("/update")
    public AjaxResult edit(@RequestBody StrategyType strategyType)
    {
        return error("不支持修改！");
    }

    /**
     * 删除策略和类型的中间表
     */
	@DeleteMapping("/del/{strategyIds}/{typeIds}")
    public AjaxResult remove(@PathVariable("strategyIds") Integer strategyIds,@PathVariable("typeIds") Integer typeIds)
    {
        return toAjax(strategyTypeService.deleteStrategyTypeByStrategyIds(strategyIds,typeIds));
    }
}
